package org.codingq92.basic.proxy.handler;

import org.codingq92.basic.proxy.iface.IAnimal;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class ProxyHandler implements InvocationHandler {

    // 目标实现类
    private final Object target;

    public ProxyHandler(IAnimal target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("proxyHandler beg");
        // 调用目标实现类的方法
        Object invoke = method.invoke(target, args);
        System.out.println("proxyHandler end");
        return invoke;
    }
}
